package com.ai.module.user.domain.vo;

import com.ai.module.mj.constant.enums.TaskAction;
import com.alibaba.fastjson2.JSONArray;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author: heJinQin
 * @create: 2024-03-28 18:20
 * @description:
 **/
@Data
@Slf4j
public class AiProductContentRecordVo {

    private String question;

    private String answer;

    private List<String> answerList;

    private Integer costTime;

    public String createdTime;

    public List<String> userUrlList;

    public List<String> aiUrlList;

    private String userFile;

    private String aiFile;

    private TaskAction action;

    public void setAiFile(String aiFile) {
        this.aiFile = aiFile;
        if (aiFile !=null){
            List<String> aiFileList = JSONArray.parseArray(aiFile, String.class);
            setAiUrlList(aiFileList);
        }
    }
    public void setUserFile(String aiFile) {
        this.aiFile = aiFile;
        if (aiFile !=null){
            try {
                List<String> aiFileList = JSONArray.parseArray(aiFile, String.class);
                setUserUrlList(aiFileList);
            }catch (Exception ex){
                setUserUrlList(Collections.singletonList(aiFile));
                log.error("JSON解析异常 [{}]",aiFile);
            }


        }
    }

    public void setAnswer(String answer) {
        this.answer = answer;
        if (StringUtils.hasText(answer)){
            try {
                setAnswerList(JSONArray.parseArray(answer,String.class));
            }catch (Exception ex){
                setAnswerList(Collections.singletonList(aiFile));
                log.error("JSON解析异常 [{}]",aiFile);
            }
        }
    }
}
